package convertor;

import java.text.ParseException;
import java.util.Date;
import java.util.Map;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.struts2.util.StrutsTypeConverter;

public class DateTypeConvertor extends StrutsTypeConverter {

	@Override
	public Object convertFromString(Map paramMap, String[] values,
			Class paramClass) {
		String value=values[0];
		Date date=null;
		try {
			date=DateUtils.parseDate(value, "dd/MM/yyyy");
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}

	@Override
	public String convertToString(Map paramMap, Object o) {
		Date date=(Date)o;
		return DateFormatUtils.format(date, "yyyy-MM-dd");
	}

}
